using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using CMS.Core.DataInterfaces;
using CMS.Core.Domain;
using CMS.Data;
using AjaxPro;

namespace CMS.Presenters
{
    public class SelectVanBanPresenter
    {
        List<VanBan> vbList;
        ISelectVanBanView view;
        IVanBanDao vbDao;
     
       
        //Attaches this presenter to the view's events.
        public SelectVanBanPresenter(ISelectVanBanView view)
        {
            this.view = view;
            this.vbDao = new VanBanDao();
            this.vbDao = NHibernateDaoFactory.Instance.GetVanBanDao();
            SubscribeViewToEvents();
        }

        public SelectVanBanPresenter()
        {
           
        }

        void SubscribeViewToEvents()
        {
            view.Load += OnViewLoad;
        }

        void OnViewLoad(object sender, EventArgs e)
        {
            if (!view.IsPostBack)
            {
                LoadViewFromModel();
                //view.DataBind();
            }
        }

        void LoadViewFromModel()
        {
            this.vbList = this.vbDao.GetAllOrderField("TenVanBan", true);
            view.VanBanList = this.vbList;
        }

        [AjaxMethod]
        public IList<VanBan> LoadVanBan()
        {
            this.vbDao = new VanBanDao();
            List<VanBan> vbList = this.vbDao.GetAllOrderField("TenVanBan", true);

            return vbList;
        }

        //[AjaxMethod]
        //public IList<NguoiSuDungEx> Ajax_LoadLeaders()
        //{
        //    this.nsdDao = new NguoiSuDungDao();
        //    List<NguoiSuDung> nsdList = this.nsdDao.GetLeaders(true);

        //    return this.nsdDao.ConvertToNguoiSuDungEx(nsdList);
        //}

        ////Check stand for Nguoi xu ly van ban
        //[AjaxMethod]
        //public string[] LoadStandForNguoiXuLy(string keyword)
        //{
        //    NguoiSuDung obj = null;
        //    this.nsdDao = new NguoiSuDungDao();
        //    obj = this.nsdDao.GetNguoiSuDungOfVietTat(keyword);
        //    string[] arr = new string[] { };
        //    if (obj != null)
        //    {
        //        arr = new string[] { obj.TenNguoiSuDung, obj.ID, obj.TenTruyCap };
        //    }
        //    return arr;
        //}

        ////Check stand for Nguoi xu ly van ban dang nguois xu dung extend
        //[AjaxMethod]
        //public string[] LoadStandForSelectPersonEX(string keyword)
        //{
        //    NguoiSuDung obj = null;
        //    this.nsdDao = new NguoiSuDungDao();
        //    obj = this.nsdDao.GetNguoiSuDungOfVietTat(keyword);
        //    string[] arr = new string[] { };
        //    if (obj != null)
        //    {
        //        arr = new string[] { obj.TenNguoiSuDung, obj.ID, obj.ChucVu, obj.TenTruyCap };
        //    }
        //    return arr;
        //}
    }
}
